<?php

class CommentService{
	
    public static function topNewComments($limit = 10){
        $baseCommentArr = CommentAR::topNewComments($limit);
        $bookIdArr = array();
        $len = count($baseCommentArr);
        for($i = 0; $i < $len; $i++){
            $bookIdArr[] = $baseCommentArr[$i]['fk_book'];
        }
        $bookIdAndName = BookAR::batchGetNamesByIds($bookIdArr);
        for($i = 0; $i < $len; $i++){
            $baseCommentArr[$i]['book_name'] = $bookIdAndName[$baseCommentArr[$i]['fk_book']];
        }
        return $baseCommentArr;
    }
    
    public static function save($bookId,$commentContent){
    	if(DiskGenAR::commentCanGenDiskToday(User::id())){
			$genSize = DiskGenAR::forComment(User::id(),User::name());
			UserAR::increDiskSize(User::id(),$genSize);    		
    	}
    	BookAR::increCommentTimes($bookId);
    	return CommentAR::saveComment($bookId,$commentContent);    	
    }
}
